package com.pz.chat.controller;

import com.pz.chat.service.ChatMessageService;
import com.pz.chat.service.MemberFocusService;
import com.pz.chat.vo.AddFocusApplyReqVo;
import com.pz.chat.vo.FocusApplyItemResVo;
import com.pz.chat.vo.HandleFocusApplyReqVo;
import com.pz.chat.vo.MemberFocusSearchReqVo;
import com.pz.gulimall.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Autowired
    private ChatMessageService chatMessageService;
    @Autowired
    private MemberFocusService memberFocusService;

    /**
     * 获取聊天对象的基本信息和所有聊天记录
     * @param params {fromId, toId}
     * @return 聊天对象的基本信息(userInfo), 两者的所有聊天消息(chatMsgList)
     */
    @PostMapping("/get-targetInfo")
    public R getChatTargetInfo(@RequestBody Map<String, Object> params) {
        return chatMessageService.getChatTargetInfo(params);
    }

    /**
     * 获取{userId}的好友申请列表
     */
    @GetMapping("/list-focus/{userId}")
    public R getFocusApply(@PathVariable Long userId) {
        List<FocusApplyItemResVo> list1 = memberFocusService.listFocusApply(userId);
        List<FocusApplyItemResVo> list2 = memberFocusService.listMyApply(userId);
        Map<String, Object> ans = new HashMap<>();
        ans.put("otherApplyList", list1);
        ans.put("ownApplyList", list2);
        return R.okData(ans);
    }

    /**
     * 添加关注
     */
    @PostMapping("/add-focus")
    public R addFocus(@RequestBody AddFocusApplyReqVo vo) {
        memberFocusService.addFocus(vo);
        return R.ok("申请成功");
    }

    /**
     * 处理好友申请
     */
    @PostMapping("/handle-focusApply")
    public R handleFocusApply(@RequestBody HandleFocusApplyReqVo vo) {
        memberFocusService.handle(vo);
        return R.ok();
    }

    /**
     * 搜索我的关注和全局好友
     */
    @PostMapping("/query-member-focus")
    public R getMemberAboutFocus(@RequestBody @Valid MemberFocusSearchReqVo vo){
        return memberFocusService.queryMemberFocus(vo);
    }
}
